package com.zjuh.qss.biz.ao.impl;

import java.util.Arrays;

import wint.help.biz.result.Result;
import wint.help.biz.result.ResultSupport;
import wint.help.biz.result.ResultType;

import com.taobao.api.domain.TaobaokeItem;
import com.zjuh.qss.biz.ao.TaokeQueryAO;
import com.zjuh.qss.biz.bo.TaobaoOpenBO;
import com.zjuh.qss.biz.bo.TaokeUtil;
import com.zjuh.qss.biz.domain.TopicItemDO;
import com.zjuh.qss.biz.resultcodes.TaobaoOpenResultCodes;

public class TaokeQueryAOImpl extends BaseAO implements TaokeQueryAO {

	private TaobaoOpenBO taobaoOpenBO;
	
	@Override
	public Result queryByItemId(long itemId) {
		Result result = new ResultSupport(false);
		try {
			TaobaokeItem taobaokeItem = taobaoOpenBO.queryTaobaokeItem(itemId);
			if (taobaokeItem == null) {
				result.setResultCode(TaobaoOpenResultCodes.TAOKEITEM_NOT_EXIST, ResultType.CURRENT_TARGET);
				return result;
			}
			TopicItemDO topicItem = TaokeUtil.toTopicItem(taobaokeItem);
			result.getModels().put("topicItems", Arrays.asList(topicItem));
			result.setSuccess(true);
		} catch (Exception e) {
			log.error("queryByItemId error", e);
		}
		return result;
	}

	public void setTaobaoOpenBO(TaobaoOpenBO taobaoOpenBO) {
		this.taobaoOpenBO = taobaoOpenBO;
	}

}
